#include "./SessionStorage.h"

void MemorySessionStorage::save(std::shared_ptr<Session> session)
{
    this->sessions_[session->getId()] = session;
}

std::shared_ptr<Session> MemorySessionStorage::load(const std::string &sessionId)
{
    auto it = this->sessions_.find(sessionId);
    if (it == sessions_.end()) // 不存在
    {
        return nullptr;
    }

    if (it->second->isExpired()) // 过期
    {
        this->sessions_.erase(it);
        return nullptr;
    }

    return it->second;
}

void MemorySessionStorage::remove(const std::string &sessionId)
{
    this->sessions_.erase(sessionId);
}